package com.taotao.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.taotao.common.pojo.EasyUITreeNode;
import com.taotao.common.pojo.TaotaoResult;
import com.taotao.content.service.ContentCatagoryService;
import com.taotao.pojo.TbItem;

/**
 * 内容分类管理
 * @author Administrator
 *
 */
@Controller
public class ContentCategoryController {

	//1.注入content-service
	@Autowired
	private ContentCatagoryService service;
	
	//url : '/content/category/list',
	//resultType:json
	@RequestMapping(value="/content/category/list",method=RequestMethod.GET)
	@ResponseBody
	public List<EasyUITreeNode> showContentCategory(@RequestParam(value="id",defaultValue="0") long parentId ,Model model){
		return service.getContentCategory(parentId);
	}
	
	//url:"/content/category/create"
	//method : post
	@RequestMapping(value="/content/category/create",method=RequestMethod.POST)
	@ResponseBody
	public TaotaoResult addContentCategory(long parentId,String name) {
		return service.addContentCategory(parentId, name);
	}
	
	//url:"/content/category/delete/"
	//method: post
	@RequestMapping(value="/content/category/delete/",method=RequestMethod.POST)
	@ResponseBody
	public TaotaoResult deleteContentCategory(long id,String nodes1) {
		return service.deleteContentCategoryByRec(id);
	}
	
	//  $.post("/content/category/update",{id:node.id,name:node.text});
	@RequestMapping(value="/content/category/update",method=RequestMethod.POST)
	public void updateContentCategory(long id,String name) {
		service.updateContentCategory(id, name);
	}
}
